package com.itheima.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

public class Test03 {
    public static void main(String[] args) throws IOException {
        //获取路径
        String path = Test03.class.getClassLoader().getResource("student.xml").getPath();
        //解析文档
        Document document = Jsoup.parse(new File(path), "utf-8");
        //得到所有student对象
        Elements student = document.getElementsByTag("student");
        System.out.println(student);

        System.out.println("-------------------------");
        //得到属性名为id的对象
        Elements id = document.getElementsByAttribute("id");
        System.out.println(id);
        System.out.println("=================================");
        //获取number值为heima_0001的对象
        Elements elements = document.getElementsByAttributeValue("number", "heima_0001");
        System.out.println(elements);
        System.out.println("-----------------------");
        //获取id属性值对象
        Element element = document.getElementById("itcast");
        System.out.println(element);


    }
}
